'''
@Author: shj
@Date: 2020-05-30 23:28:25
@LastEditTime: 2020-06-03 10:17:55
@LastEditors: shj
@Description:  反转链表
@FilePath: /python3/algorithms/offer_code/3_reverse_arrayList.py
'''
'''
题目描述
输入一个链表，按链表从尾到头的顺序返回一个ArrayList。
'''
'''
解题思路
法1 链表先入栈，后输出
法2 数组反转
'''


class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(ListNode):
    # 返回从尾部到头部的列表值序列，例如[1,2,3]
    def printListFromTailToHead(self, listNode):
        # write code here
        l = []
        head = listNode
        while head:
            l.append(head.val)
            head = head.next
        return l[::-1]
